<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<title>表单提交</title>
</head>

<body>
	<h2>您好,尊敬的用户</h2>
		<p>~欢迎您，尊敬的大帅比~</p>
	<h1>留言板</h1>
	<!-- <p>张三说：666</p> -->
	<textarea style="width: 200px;height: 150px;"></textarea>
	<button style="width: 205px; height:30px">发表</button>
	
	<script>
		//寻找问号后面的数据全部拿来
		// var url=location.search;
		//解码
			var url=decodeURI(location.search);
			function getObj(url){
				//截断
				let str=url.substr(1).split('&').map(o=>o.split('='));
				let Obj={};
				str.forEach(x=>Obj[x[0]]=x[1])
				return Obj;
			};
		
			$(function(){
				var user=url.length ? getObj(url):{}
				$('h2').text('您好,尊敬的用户'+user.name);
				$('button').click(function(){
					let txt=$('textarea').val();
					let p=`<p>${user.name}说：${txt}</P>
					<P style='text-align:end'>${new Date()}</P>
					`
					txt.length ? $('textarea').before(p):alert('抱歉，您不能发表空评论~')
				})
			})
			
	</script>
</body>
</html>
